package com.shop.loan.service.impl;

import com.shop.loan.mapper.FeedbackByMybatisMapper;
import com.shop.loan.model.common.Code;
import com.shop.loan.model.common.ResResult;
import com.shop.loan.model.entity.FeedbackByMybatis;
import com.shop.loan.model.vo.FeedbackVo;
import com.shop.loan.service.FeedbackService;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import javax.annotation.Resource;
import java.util.Date;

@Service
public class FeedbackServiceImpl implements FeedbackService {

    @Resource
    FeedbackByMybatisMapper feedbackByMybatisMapper;

    @Override
    public ResResult add(FeedbackVo feedbackVo) {
        if (!StringUtils.hasText(feedbackVo.getContent())) {
            return new ResResult(Code.PARAM_LACK);
        }
        FeedbackByMybatis feedbackByMybatis = new FeedbackByMybatis();
        feedbackByMybatis.setAttachment(feedbackVo.getAttachment());
        feedbackByMybatis.setContent(feedbackVo.getContent());
        feedbackByMybatis.setName(feedbackVo.getName());
        feedbackByMybatis.setWx(feedbackVo.getWx());
        feedbackByMybatis.setQq(feedbackVo.getQq());
        feedbackByMybatis.setPhone(feedbackVo.getPhone());
        feedbackByMybatis.setCreateTime(new Date());
        feedbackByMybatis.setStatus(false);
        feedbackByMybatis.setUserId(feedbackVo.getOpId());
        feedbackByMybatisMapper.insertSelective(feedbackByMybatis);
        return new ResResult(Code.SUCCESS);
    }
}
